<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>boost/python/long.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../object_wrappers.html" title="Chapter 3. Object Wrappers">
<link rel="prev" href="boost_python_list_hpp.html" title="boost_python_list.hpp">
<link rel="next" href="boost_python_object_hpp.html" title="boost/python/object.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_list_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../object_wrappers.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_object_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="object_wrappers.boost_python_long_hpp"></a><a class="link" href="boost_python_long_hpp.html" title="boost/python/long.hpp">boost/python/long.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.class_long">Class
        <code class="computeroutput"><span class="identifier">long_</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_long_hpp.introduction"></a><a class="link" href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
          Exposes a <a class="link" href="../concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a>
          for the Python <a href="http://www.python.org/doc/current/lib/typesnumeric.html" target="_top">long</a>
          integer type.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_long_hpp.class_long"></a><a class="link" href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.class_long" title="Class long_">Class
        <code class="computeroutput"><span class="identifier">long_</span></code></a>
</h3></div></div></div>
<p>
          Exposes the <a href="http://www.python.org/doc/current/lib/typesnumeric.html" target="_top">numeric
          type protocol</a> of Python's built-in <code class="computeroutput"><span class="keyword">long</span></code>
          type. The semantics of the constructors and member functions defined below
          can be fully understood by reading the <a class="link" href="../concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a>
          concept definition. Since <code class="computeroutput"><span class="identifier">long_</span></code>
          is publicly derived from <a class="link" href="boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object" title="Class object"><code class="computeroutput"><span class="identifier">object</span></code></a>, the public <code class="computeroutput"><span class="identifier">object</span></code> interface applies to <code class="computeroutput"><span class="identifier">long_</span></code> instances as well.
        </p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
  <span class="keyword">class</span> <span class="identifier">long_</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">object</span>
  <span class="special">{</span>
   <span class="keyword">public</span><span class="special">:</span>
      <span class="identifier">long_</span><span class="special">();</span> <span class="comment">// new long_</span>

      <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
      <span class="keyword">explicit</span> <span class="identifier">long_</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">rhs</span><span class="special">);</span>

      <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">&gt;</span>
      <span class="identifier">long_</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">rhs</span><span class="special">,</span> <span class="identifier">U</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">base</span><span class="special">);</span>
  <span class="special">};</span>
<span class="special">}}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="object_wrappers.boost_python_long_hpp.example"></a><a class="link" href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">python</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>

<span class="comment">// compute a factorial without overflowing</span>
<span class="identifier">python</span><span class="special">::</span><span class="identifier">long_</span> <span class="identifier">fact</span><span class="special">(</span><span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
<span class="special">{</span>
   <span class="keyword">if</span> <span class="special">(</span><span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span>
      <span class="keyword">return</span> <span class="identifier">python</span><span class="special">::</span><span class="identifier">long_</span><span class="special">(</span><span class="number">1</span><span class="special">);</span>
   <span class="keyword">else</span>
      <span class="keyword">return</span> <span class="identifier">n</span> <span class="special">*</span> <span class="identifier">fact</span><span class="special">(</span><span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_list_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../object_wrappers.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_object_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>
